package app.netant.book.bookbao99;

import org.jsoup.select.Elements;

import app.netant.book.base.BaseDetail;
/**
 * 
 * @author JiaJ
 *
 */
public class BookBao99Detail extends BaseDetail {

	public BookBao99Detail(String netSite) {
		super(netSite);
		this.preHref = "https://www.bookbao99.net";
	}

	@Override
	public void analyseTitle() {
		Elements parts = this.select(".wp.b2 .am-panel-bd.infoleft #info h1");
		if(parts.size()>0){
			String title = parts.get(0).text();
			System.out.println("【Title】:"+title);
			this.entity.setNovelName(title);
			this.entity.setNovelFullName(title+".txt");			
		}
	}

	@Override
	public void analyseTags() {
		Elements parts = this.select(".wp.b2 .am-panel-bd.infoleft #info p");
		for(int i=0;i<parts.size();i++){
			String tags = parts.get(i).text();
			int idx = tags.indexOf("：");
			if(idx>0){
				String tagName = tags.substring(0,idx).trim();
				String tagValue = tags.substring(idx+1).trim();
				System.out.println("【Tag】:"+tagName+"="+tagValue);
				this.entity.setTag(tagName, tagValue);
			}
		}
	}

	@Override
	public void analyseMemo() {
		Elements parts = this.select(".wp.b2 .infocontent");
		if(parts.size()>0){
			String memo = parts.get(0).text();
			System.out.println("【Memo】:"+memo);
			this.entity.setNovelMemo(memo);
		}
	}

	@Override
	public void analyseHref() {
		Elements parts = this.select(".wp.b2 .btnzone a.am-btn");
		for(int i=0;i<parts.size();i++){
			String txt = parts.get(i).text();
			if(txt.indexOf("下载")>=0){
				String href = parts.get(i).attr("href");
				if(href.startsWith("/")){
					href = this.preHref + href;
				}
				System.out.println("【Url】:"+href);
				
				BookBao99Detail detail = new BookBao99Detail(href);
				String url = detail.stepHref();
				System.out.println("【Href】:"+url);
				
				this.entity.setDownPath(url);
				
				break;
			}
		}
	}
	
	public String stepHref(){
		Elements parts = this.select(".index_div .info_l .info_div .info_buttondiv a");
		if(parts.size()>0){
			String href = parts.get(0).attr("href");
			return href;
		}else{
			return null;
		}
	}
	
	@Override
	public void analyseType() {
		Elements parts = this.select(".wp.b2 .bt10 ol.am-breadcrumb li a");
		if(parts.size()>1){
			String type = parts.get(1).text();
			System.out.println("【Type】:"+type);
			this.entity.setNovelType(type);
		}
	}
	
	public static void main(String[] args) {
		BookBao99Detail detail = new BookBao99Detail("https://www.bookbao99.net/book/201707/06/id_XNTgyNzMw.html");
		detail.test();
	}



}
